```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis Cluster 集群模式详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            background-color: #f9fafb;
            line-height: 1.6;
        }
        .container {
            max-width: 1200px;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero {
            background: linear-gradient(135deg, #6b46c1 0%, #805ad5 100%);
            color: white;
            border-radius: 0 0 20px 20px;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }
        .card {
            transition: all 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            background-color: white;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }
        .section-title {
            position: relative;
            padding-bottom: 0.5rem;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 3px;
            background: linear-gradient(90deg, #6b46c1 0%, #805ad5 100%);
            border-radius: 3px;
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background: linear-gradient(135deg, #6b46c1 0%, #805ad5 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        .code-block {
            font-family: 'Courier New', Courier, monospace;
            background-color: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
        }
        .footer {
            background-color: #1a202c;
            color: white;
            padding: 2rem 0;
            margin-top: 4rem;
        }
        .footer a:hover {
            color: #a0aec0;
        }
        .mermaid {
            background-color: white;
            padding: 1rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            margin: 2rem 0;
        }
        .image-container {
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin: 2rem 0;
        }
        .image-container img {
            width: 100%;
            height: auto;
            display: block;
        }
        .summary-item {
            border-left: 3px solid #6b46c1;
            padding-left: 1rem;
            margin-bottom: 1rem;
            transition: all 0.3s ease;
        }
        .summary-item:hover {
            background-color: #f3f4f6;
            transform: translateX(5px);
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <section class="hero py-16 px-4 md:px-8 mb-12">
        <div class="container mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-8 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4">Redis Cluster 集群模式</h1>
                    <p class="text-xl md:text-2xl mb-6 opacity-90">突破单节点限制的高可用分布式解决方案</p>
                    <p class="text-lg opacity-85 mb-8">Redis Cluster 是 Redis 的高级集群模式，通过数据分片和分布式存储实现了负载均衡和高可用性。每个节点负责一部分数据，称为槽位，通过分片实现大规模数据存储。</p>
                    <div class="flex space-x-4">
                        <a href="#principles" class="px-6 py-3 bg-white text-purple-700 rounded-lg font-medium hover:bg-opacity-90 transition">核心原理</a>
                        <a href="#implementation" class="px-6 py-3 bg-white bg-opacity-20 rounded-lg font-medium hover:bg-opacity-30 transition">配置实现</a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-full max-w-md">
                        <div class="absolute -top-8 -left-8 w-32 h-32 bg-purple-300 rounded-full opacity-20"></div>
                        <div class="absolute -bottom-8 -right-8 w-32 h-32 bg-purple-400 rounded-full opacity-20"></div>
                        <div class="relative z-10">
                            <div class="mermaid">
                                graph TD
                                    A[Redis Cluster] --> B[数据分片]
                                    A --> C[高可用性]
                                    A --> D[负载均衡]
                                    B --> E[16384个哈希槽]
                                    B --> F[CRC16算法]
                                    C --> G[主从复制]
                                    C --> H[自动故障转移]
                                    D --> I[均匀分布]
                                    D --> J[动态迁移]
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto px-4 md:px-8 mb-16">
        <!-- Principles Section -->
        <section id="principles" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Redis Cluster 原理</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <p class="mb-6">Redis Cluster 将整个数据集划分为 16384 个哈希槽，每个槽对应一个编号。这些槽被均匀分布在集群中的各个节点上。每个节点负责管理一部分槽，通过哈希算法，将键值对映射到具体的哈希槽上。</p>
                    
                    <div class="card p-6 mb-6">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-network-wired"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3 text-center">节点通信</h3>
                        <p class="text-gray-700">节点之间使用 gossip 协议进行通信，通过集群总线来共享集群的信息，包括节点拓扑、槽的分配情况等。这样的去中心化通信方式有助于维护整个集群的一致性。</p>
                    </div>
                </div>
                
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1705566577075-8c9fea78-2590-4a1c-8862-968f1f75e3ea.png" alt="Redis Cluster 架构图">
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1705566821732-89508f8f-75dd-44e8-b0ab-a4743c821ae8.png" alt="Redis 数据分片">
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4">数据分片与槽位</h3>
                    <p class="mb-6">Redis Cluster 将数据分为 16384 个槽位，每个节点负责管理一部分槽位。当客户端向 Redis Cluster 发送请求时，Cluster 会根据键的哈希值将请求路由到相应的节点。</p>
                    
                    <div class="card p-6">
                        <div class="flex items-center mb-3">
                            <div class="w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-hashtag text-purple-600"></i>
                            </div>
                            <h4 class="font-medium">哈希算法</h4>
                        </div>
                        <p class="text-gray-700">Redis Cluster 使用 CRC16 算法计算键的哈希值，然后对 16384 取模，得到槽位编号。</p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Implementation Section -->
        <section id="implementation" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">配置和实现</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-semibold mb-4">1. 准备六个节点</h3>
                    <p class="mb-6">使用 Docker Compose 快速部署六个 Redis 节点，三主三从。</p>
                    
                    <div class="code-block">
                        <pre><code class="language-yaml">version: "3.1"
services:
  redis1:
    image: daocloud.io/library/redis:5.0.7
    restart: always
    container_name: redis1
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 7001:7001
      - 17001:17001
    volumes:
      - ./conf/redis1.conf:/usr/local/redis/redis.conf
    command: ["redis-server","/usr/local/redis/redis.conf"]
  redis2:
    image: daocloud.io/library/redis:5.0.7
    restart: always
    container_name: redis2
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 7002:7002
      - 17002:17002
    volumes:
      - ./conf/redis2.conf:/usr/local/redis/redis.conf
    command: ["redis-server","/usr/local/redis/redis.conf"]  
  redis3:
    image: daocloud.io/library/redis:5.0.7
    restart: always
    container_name: redis3
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 7003:7003
      - 17003:17003
    volumes:
      - ./conf/redis3.conf:/usr/local/redis/redis.conf
    command: ["redis-server","/usr/local/redis/redis.conf"]  
  redis4:
    image: daocloud.io/library/redis:5.0.7
    restart: always
    container_name: redis4
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 7004:7004
      - 17004:17004
    volumes:
      - ./conf/redis4.conf:/usr/local/redis/redis.conf
    command: ["redis-server","/usr/local/redis/redis.conf"]  
  redis5:
    image: daocloud.io/library/redis:5.0.7
    restart: always
    container_name: redis5
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 7005:7005
      - 17005:17005
    volumes:
      - ./conf/redis5.conf:/usr/local/redis/redis.conf
    command: ["redis-server","/usr/local/redis/redis.conf"]  
  redis6:
    image: daocloud.io/library/redis:5.0.7
    restart: always
    container_name: redis6
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 7006:7006
      - 17006:17006
    volumes:
      - ./conf/redis6.conf:/usr/local/redis/redis.conf
    command: ["redis-server","/usr/local/redis/redis.conf"]</code></pre>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4">2. 修改配置文件</h3>
                    <p class="mb-6">为每个节点配置集群相关参数，确保正确通信。</p>
                    
                    <div class="code-block mb-8">
                        <pre><code class="language-nginx"># redis.conf
# 指定redis的端口号
port 7001
# 开启Redis集群
cluster-enabled yes
# 集群信息的文件
cluster-config-file nodes-7001.conf
# 集群的对外ip地址
cluster-announce-ip 192.168.199.109
# 集群的对外port
cluster-announce-port 7001
# 集群的总线端口
cluster-announce-bus-port 17001
# 关闭保护模式
protected-mode no</code></pre>
                    </div>
                    
                    <h3 class="text-2xl font-semibold mb-4">3. 创建集群</h3>
                    <p class="mb-4">使用 Redis 自带的工具创建集群，自动分配主从关系。</p>
                    
                    <div class="bg-gray-100 p-4 rounded-lg mb-6">
                        <p class="font-mono text-sm">redis-cli --cluster create 192.168.199.109:7001 192.168.199.109:7002 192.168.199.109:7003 192.168.199.109:7004 192.168.199.109:7005 192.168.199.109:7006 --cluster-replicas 1</p>
                    </div>
                    
                    <p class="text-gray-700"><i class="fas fa-info-circle text-purple-600 mr-1"></i> <code>cluster-replicas</code> 表示从节点的数量，1代表每个主节点都有一个从节点。</p>
                    
                    <div class="image-container mt-6">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1705567356844-fe30ce74-3d3e-4a33-bfed-5e5412c28e2d.png" alt="Redis 集群创建成功">
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Application Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">场景应用</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="card p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-database text-purple-600"></i>
                        </div>
                        <h3 class="font-semibold text-lg">大规模数据存储</h3>
                    </div>
                    <p class="text-gray-700">通过数据分片，突破单节点内存限制，支持TB级别的数据存储。</p>
                </div>
                
                <div class="card p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-tachometer-alt text-purple-600"></i>
                        </div>
                        <h3 class="font-semibold text-lg">高性能要求场景</h3>
                    </div>
                    <p class="text-gray-700">通过负载均衡，将请求分散到多个节点，提高系统整体性能。</p>
                </div>
                
                <div class="card p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-shield-alt text-purple-600"></i>
                        </div>
                        <h3 class="font-semibold text-lg">高可用性要求场景</h3>
                    </div>
                    <p class="text-gray-700">通过自动故障转移机制，确保服务在节点故障时持续可用。</p>
                </div>
            </div>
        </section>
        
        <!-- Summary Section -->
        <section>
            <h2 class="text-3xl font-bold mb-8 section-title">核心要点总结</h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="summary-item">
                    <h3 class="font-semibold text-lg mb-2">哈希槽分配</h3>
                    <p class="text-gray-700">Redis Cluster 将整个数据集划分为 16384 个哈希槽，每个槽对应一个编号。这些槽被均匀分布在集群中的各个节点上。</p>
                </div>
                
                <div class="summary-item">
                    <h3 class="font-semibold text-lg mb-2">节点通信</h3>
                    <p class="text-gray-700">节点之间使用 gossip 协议进行通信，通过集群总线共享集群信息，维护集群一致性。</p>
                </div>
                
                <div class="summary-item">
                    <h3 class="font-semibold text-lg mb-2">主从复制</h3>
                    <p class="text-gray-700">每个哈希槽对应一个主节点和零个或多个从节点，从节点可升级为主节点实现故障转移。</p>
                </div>
                
                <div class="summary-item">
                    <h3 class="font-semibold text-lg mb-2">数据迁移</h3>
                    <p class="text-gray-700">集群会自动进行数据迁移和槽重新分配，确保负载均衡。</p>
                </div>
                
                <div class="summary-item">
                    <h3 class="font-semibold text-lg mb-2">客户端路由</h3>
                    <p class="text-gray-700">客户端直接与负责槽的节点通信，无需中心节点介入。</p>
                </div>
                
                <div class="summary-item">
                    <h3 class="font-semibold text-lg mb-2">动态扩展</h3>
                    <p class="text-gray-700">支持运行时动态添加或删除节点，集群自动调整。</p>
                </div>
            </div>
            
            <div class="image-container mt-8">
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1705567387179-a92e1baf-c155-4aa4-a11d-1218d3454b88.png" alt="Redis Cluster 成功示例">
            </div>
        </section>
    </div>
    
    <!-- Footer -->
    <footer class="footer">
        <div class="container mx-auto px-4 md:px-8 text-center">
            <div class="mb-4">
                <h3 class="text-xl font-bold">技术小馆</h3>
            </div>
            <div>
                <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition">http://www.yuque.com/jtostring</a>
            </div>
        </div>
    </footer>
    
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```